# -*- encoding:utf-8 -*-
"""
@作者：ven
@文件名：depart.py
@时间：2021-08-20  16:28
@文档说明:
"""
import json

from common.GetConfig import config_ip
from common.Request import Request


class Depart():

    def depart_add(self, data, test_api_login):
        '''新增部门'''
        return Request().post(url=config_ip() + '/departments', data=json.dumps(data),
                                 headers={'token': '{0}'.format(test_api_login),
                                          'Content-Type': 'application/json; charset=UTF-8',
                                          'X-Requested-With': 'XMLHttpRequest'})

    def depart_list(self,data,test_api_login):
        '''部门列表，获取部门ID'''
        return Request().get(url=config_ip() + '/departments/list',params=data,headers={'token': '{0}'.format(test_api_login),
                                          'Content-Type': 'application/json; charset=UTF-8',
                                          'X-Requested-With': 'XMLHttpRequest'})

    def depart_edit(self,data, test_api_login):
        #data = {"id":"883240725338120192","thirdExchangeCode":"","parentDepartId":"1","name":"C++编辑","shortName":"C++","orderNum":"","parentDepartName":"总部门","type":"0","contractTelephone":"","remarks":""}
        '''编辑部门'''
        return Request().put(url=config_ip() + '/departments', data=json.dumps(data),
                              headers={'token': '{0}'.format(test_api_login),
                                       'Content-Type': 'application/json; charset=UTF-8',
                                       'X-Requested-With': 'XMLHttpRequest'})

    def depart_del(self,id,test_api_login):
        '''删除部门'''
        return Request().delete(url=config_ip()+'/departments/{}'.format(id),headers={'token': '{0}'.format(test_api_login),
                                          'Content-Type': 'application/json; charset=UTF-8',
                                          'X-Requested-With': 'XMLHttpRequest'})
